/****************************************************************************************************

Created Date : 28/12/2011
Author : Arun Ramachandran
Purpose: Trigger will populate the Order SFDC link in the corresponding DIGITAL EXPRESS record.
Version :1.0

Update: [Arun [1/9] ] - Updated API version to 22.0 from 23.0
                      - Added check for Opportunity RecordType value.

****************************************************************************************************/

trigger OORDigitalExpressOppty on Opportunity (after insert) {

    Map<ID,ID> OppDEIds = new Map<ID,ID>();
    list<Digital_Express__c> DEList = new list<Digital_Express__c>();
    ID SFAOORRenewalrecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Renewals');
    for(Opportunity Opp: trigger.new){
        
        //Adding check for Opportunity Recordtype Value in the if Condition. Updated by Arun Ramachandran on 1/9/2012
        //--------------------------------------------------------------------------------------------------------------
        
        if(Opp.Opportunity_Type__c=='Digital Express' && Opp.Digital_Express_ID__c!=NULL && Opp.RecordTypeId == SFAOORRenewalrecordTypeID){
                OppDEIds.put(Opp.Digital_Express_Id__c,Opp.Id);
                           
        }    
    }
    
    If(OppDEIds.size()>0){
        for(Digital_Express__c DErec: [Select Id from Digital_Express__c where Id IN: OppDEIds.KeySet() ]){
                DERec.SFDC_Order_ID__c = OppDEIds.get(DErec.Id);
                DEList.add(DERec);
        }
        Try{                  
              Update DEList;
           }
        Catch(DMLException e){
              system.debug('DML Exception'+e);
           }

    }
    
    
}